/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_Studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

#include "引擎枚举数据.h"
#include "引擎数据类型.h"
#include "../结构数据.h"


/*typedef struct {
	vec2	L_point;
	vec2	R_point;
	float32	value;
	float32	time;
	uint32  ID;
	uint32  Color;
}S_CurvePoint;*/



typedef struct {
	uvec2*	端点索引;
	uint64	count;
}S_曲线段;

typedef struct {
	S_曲线** 曲线;
	uint32   count;
	int8     name[32];
	void*    ObPtr;
}S_曲线通道;


typedef struct {
	S_List* 曲线通道;
	uint32	通道num;
}S_动画曲线组;




#define DEF_曲线点(c) ((S_CurvePoint*)c->ptr_userData)
#define DEF_曲线通道(c) ((S_曲线通道*)c->ptr_userData)



S_曲线*			f_an_创建曲线A();
void			f_an_销毁曲线A(S_曲线* curve);



S_曲线通道*		f_an_创建曲线通道(uint32 通道数量);
void			f_an_销毁曲线通道(S_曲线通道* curve);
S_曲线通道*		f_an_拷贝曲线通道(const S_曲线通道* 源);



S_动画曲线组*	f_an_创建曲线层();
void			f_an_销毁曲线层(S_动画曲线组* 曲线通道);
S_动画曲线组*	f_an_拷贝曲线层(S_动画曲线组* 源);

S_曲线通道*		f_an_添加曲线通道(S_动画曲线组* 曲线层, uint32 通道数量);
void            f_an_添加曲线通道(S_动画曲线组* 曲线层, S_曲线通道* 曲线通道);
void            f_an_清除曲线通道(S_动画曲线组* 曲线层);
//void			f_an_添加曲线点(S_曲线通道* 曲线通道, float32 时间, float32 值, const vec2& 左手柄, const vec2& 右手柄);


void			f_an_添加钳制曲线点(S_曲线* 曲线, const vec2& value, const vec2& 左手柄, const vec2& 右手柄, uint32 ID, const S_RGBA8UI& color = { 0,0,0,255 });
void			f_an_添加曲线点(S_曲线* 曲线, const vec2& value, const vec2& 左手柄, const vec2& 右手柄, uint32 ID, const S_RGBA8UI& color = { 0,0,0,255 });
void			f_an_删除曲线点(S_曲线* 曲线, int32 time);

vec3			f_an_曲线值(S_曲线通道* 通道, float32 时间);
//S_CurvePoint*	f_an_get曲线点(S_曲线通道* 通道曲线, uint32 id);
//void			f_an_曲线值排序(S_曲线通道* 通道曲线);


S_CurvePoint*	f_an_get曲线点A(S_曲线* 曲线, int32 id);
void			f_an_钳制曲线值排序(S_曲线* 曲线);
void			f_an_曲线值排序(S_曲线* 曲线);
int32			f_an_移除曲线重合点(S_曲线* 曲线, S_CurvePoint* point, float32 最小距离);


void			f_an_钳制曲线自动控制点(S_曲线* 曲线);
void			f_an_自动控制点(S_曲线* 曲线);

float32			f_an_曲线采样(float32 采样位置, const S_曲线& curve);




int32			f_an_查找重叠帧(S_曲线* 曲线, float32 帧时间);




void		f_an_Load(S_曲线* curve, FILE* f);
void		f_an_Save(S_曲线* curve, FILE* f);



Inline void f_an_包(S_曲线* curve, S_UI8Array* 块) {
	f_core_array_包((S_Array*)curve, 块);
}
Inline const uint8* f_an_解(S_曲线* curve, const uint8* 块) {
	return f_core_array_解((S_Array*)curve, 块);
}


S_曲线通道*	f_an_Load通道(FILE* f);
void		f_an_Save通道(S_曲线通道* curve, FILE* f);

const uint8* f_an_Load通道(S_曲线通道** curve, const uint8* 块);
void f_an_Save通道(S_曲线通道* curve, S_UI8Array* 块);




